package cn.template.models.common;

import cn.template.models.exceptions.AppException;
import lombok.Data;
import org.springframework.http.HttpStatus;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;
@Data
public class CustomErrorResponse {
    private String path;
    private HttpStatus status;
    private String method;
    private String message;
    private Date requestTime;

    public CustomErrorResponse() {
    }

    public CustomErrorResponse(HttpServletRequest request, AppException ex) {
        this.method = request.getMethod();
        this.path = request.getServletPath();
        this.status = ex.getStatus();
        this.message = ex.getMessage();
        this.requestTime = new Date();
    }

    public CustomErrorResponse(HttpServletRequest request, String message) {
        this.method = request.getMethod();
        this.path = request.getServletPath();
        this.status = HttpStatus.INTERNAL_SERVER_ERROR;
        this.message = message;
        this.requestTime = new Date();
    }

    public Integer getCode() {
        return status.value();
    }
}
